﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace WebAPILib.APIs.DaZhouDianPing
{
    public class ShopInfo_Params_ToQueryStr
    {

        internal string Translate(ShopInfo_QueryParams queryParams)
        {
            //请替换AppKey以及Secret
            string appKey = DeveloperInfo.DeveloperInfo.APPkey;
            string secret = DeveloperInfo.DeveloperInfo.AppSecret;
            string value = "";
            string queryString = "";

            //准备参数
            Hashtable ht = new Hashtable();
            //ht.Add("format", "json");
            
            //ht.Add("region", "海淀区");
            //ht.Add("category", "火锅");
            //ht.Add("has_coupon", "1");
            //ht.Add("sort", "2");
            //ht.Add("limit", "1");

            

            if (!string.IsNullOrEmpty(queryParams.city))
            {
                ht.Add("city", queryParams.city);
            }

            ht.Add("limit", queryParams.limit);


            //参数按照参数名排序
            ArrayList akeys = new ArrayList(ht.Keys);
            akeys.Sort();

            //拼接字符串
            foreach (string skey in akeys)
            {
                value += skey + ht[skey].ToString();
                queryString += "&" + skey + "=" + BaseInfo.Utf8Encode(ht[skey].ToString());
            }

            StringBuilder sb = new StringBuilder();
            sb.Append(appKey);
            sb.Append(value);
            sb.Append(secret);
            value = sb.ToString();

            string url = DaoZhongDianPing_APIUrls.SearchShopsUrl + "?appkey=" + appKey + "&sign=" + BaseInfo.SHA1(value) + queryString;
            

            return url;

        }
    }
}
